//
//  MatchVC.m
//  Lucode
//
//  Created by lanou3g on 15/10/13.
//  Copyright © 2015年 liudi. All rights reserved.
//

#import "MatchVC.h"
#import "AFNetworking.h"
#import "AfnHelper.h"
#import "MatchDetailVC.h"
@interface MatchVC ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,strong)UITableView * tableView;
@property(nonatomic,strong)NSMutableDictionary * dataDict;
@end

@implementation MatchVC

-(instancetype)init
{
   
    if (self  = [super init]) {
        [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"reuse"];
        self.tableView.delegate = self;
        self.tableView.dataSource = self;
        
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    __weak typeof(self)temp = self;
    [AfnHelper getDataWithUrl:@"http://box.dwstatic.com/apiNewsList.php?action=l&newsTag=upgradenews&p=1" dic:nil sucess:^(id opreation) {
        temp.dataDict = opreation;
        [temp.tableView reloadData];
    } faile:^(id error) {
        NSLog(@"%@",error);
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark tableView 代理方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.dataDict[@"data"] count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"reuse"];
    cell.textLabel.text = self.dataDict[@"data"][indexPath.row][@"content"];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    MatchDetailVC * matchDetail = [MatchDetailVC new];
    matchDetail.index = self.dataDict[@"data"][indexPath.row][@"commentUrl"];
    [self.navigationController pushViewController:matchDetail animated:YES];
}
#pragma  mark 属性懒加载
-(UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
        [self.view addSubview:_tableView];
    }
    return _tableView;
}
-(NSMutableDictionary *)dataDict
{
    if (!_dataDict) {
        _dataDict = [NSMutableDictionary dictionary];
    }
    return _dataDict;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
